package game;

import java.util.List;
import java.util.Random;

import org.newdawn.slick.GameContainer;

import sound.SoundManager;
import util.Vector2D;
import entities.Enemy;

public class InstantSpawnWave extends EnemyWave {

	private static Random random = new Random();

	private boolean spawned;

	public InstantSpawnWave(List<Enemy> enemies) {
		super(enemies);
		spawned = false;
	}

	@Override
	public boolean isDefeated() {
		for (Enemy e : enemies) {
			if (level.isActive(e))
				return false;
		}
		return spawned;
	}

	@Override
	public void update(GameContainer gc, int delta) {
		if (!spawned) {
			for (Enemy e : enemies) {
				Vector2D pos = new Vector2D(gc.getWidth()
						- e.getImage().getWidth(), random.nextInt(gc
						.getHeight() - e.getImage().getHeight()));
				e.spawn(level, pos);
			}
			System.out.println("Enemies spawned");
			spawned = true;
		}
	}

	@Override
	public void reset() {
		for (Enemy e : enemies) {
			e.reset();
		}
		spawned = false;
		SoundManager.getSoundManager().playMusic(SoundManager.mainTheme);
	}

}
